import React, { useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

function AuthHoc({ children }) {
    function Hoc() {
        const { pathname } = useLocation()
        const token = localStorage.getItem('token')
        const WhileList = ['/login']
        const navigate = useNavigate()
        useEffect(() => {
            if (!token && !WhileList.includes(pathname)) {
                navigate('/login')
            }
        }, [token,pathname])
        return children
    }
    return <Hoc></Hoc>
}

export default AuthHoc
